<!doctype html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <title>系列管理</title>
        <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
        <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
        <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
        <script type="text/javascript" src="/webapp/js/common/config.js"></script>
    </head>
    <body>
        <div class="easyui-container-fluid">
            <div class="easyui-panel" style="border: none;">
                <div class="nav" id="nav"></div>
                <div class="easyui-panel" style="border:none;">
                    <form id="ff">
                        <div style="margin-bottom:20px;">
                            <label class="item-label">品类：</label>
                            <select id="categorySelect" name="categoryCode" class="easyui-combobox" style="width:100px;">
                            </select>
                            <label class="item-label">品牌：</label>
                            <select id="brandSelect" name="brandCode" class="easyui-combobox" style="width:100px;">
                            </select>
                            <label class="item-label">状态：</label>
                            <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用">

                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label">代码：</label>
                            <input type="text" name="code" class="easyui-textbox" style="width:100px;"/>
                            <label class="item-label">名称：</label>
                            <input type="text" name="likeName" id="likeName" class="easyui-textbox" style="width:100px;"/>
                            <span style="margin-left: 10px">
                    </span>

                            <a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>
                        </div>
                    </form>
                </div>
                <div class="table-wrapper">
                    <table id="datagrid" data-options="fitColumns:true,scrollBarSize:0">
                        <thead>
                            <tr>
                                <th data-options="field:'code',align:'center'" width="80">代码</th>
                                <th data-options="field:'name',align:'center'" width="150">名称</th>
                                <th data-options="field:'brandName',align:'center'" width="80">品牌</th>
                                <th data-options="field:'categoryName',align:'center'" width="80">品类</th>
                                <th data-options="field:'updateTime',align:'center'" width="150">修改时间</th>
                                <th data-options="field:'createTime',align:'center'" width="150">创建时间</th>
                                <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="40">状态</th>
                                <th data-options="field:'operateUser',align:'center'" width="60">操作人</th>
                                <th data-options="field:'action',align:'center',formatter:actions" width="180">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript">
        $(function () {
            initBrandSelect("brandSelect");
            initUserCategorySelect("categorySelect");
            var height = $(window).height();
            var nav_height = $("#nav")._outerHeight();
            var ff_height = $("#ff").height();
            var table_height = height - nav_height - ff_height - 40;
            $("#datagrid").css("max-height", table_height);
            $("#datagrid").datagrid({
                rownumbers: true,
                pagination: true,
                idField: "id",
                checkOnSelect: false,
                toolbar: [{
                    text: '添加系列',
                    handler: function () {
                        var category = getFormData(document.getElementById("ff")).categoryCode;
                        if (category) {
                            window.parent.addTab("添加系列", "/webapp/pages/product/series/add.html?categoryCode=" + category);
                        } else {
                            $.messager.alert("提示", "请选择品类", "warn");
                        }
                    }
                }]
            }).datagrid("getPager").pagination({
                onSelectPage: searchBy
            });
            aRecords("系列管理","/webapp/pages/product/series")
            searchBy(1, 100);
        });

        function brandFormatter(val, row) {
            return val + '' + row.brandCode;
        }

        function categoryFormatter(val, row) {
            return val + '' + row.categoryCode;
        }

        function searchBy(page, size) {
            var dtd = $.Deferred();
            var data = getFormData(document.getElementById("ff"));
            data.name = $("#likeName").textbox('getValue');
            var pager = {page: page, size: size};
            if (!size) {
                pager['page'] = 1;
                pager['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize || 100;
            }
            var jsonobj = {};
            jsonobj.entityStatus = $("#entityStatus").switchbutton("options").checked == true ? "OK" : "DISABLE";
            jsonobj = $.extend(true, jsonobj, transfer(data));
            jsonobj = JSON.stringify(jsonobj);
            $.ajax({
                url: config.url + "/series/page?" + transfer2url(pager),
                type: 'post',
                data: jsonobj,
                contentType: "application/json;charset=UTF-8",
                dataType: 'json',
                xhrFields: {withCredentials: true},
                beforeSend: function () {
                    $.messager.progress({
                        title: "请稍等",
                        interval: 50,
                        text: "数据加载中..."
                    });
                },
                complete: function () {
                    $.messager.progress("close");
                },
                success: function (data) {
                    $.messager.progress("close");
                    if (data.code == 200) {
                        $("#datagrid").datagrid("loadData", data.msg);
                        dtd.resolve();
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {

                }
            });
            return dtd.promise();
        }

    </script>
    <script type="text/javascript">
        function actions(val, row) {
            var content = "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' " +
                "style='width:60px;' onclick='edit(\"" + row.id + "\",\"" + row.categoryCode + "\")'>修改</a>&nbsp;&nbsp;";
            if (row.entityStatus == 'OK') {
                content += "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;' onclick='disable(\"" + row.id + "\")'>禁用</a>";
            }else{
                content += "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;' onclick='enable(\"" + row.id + "\")'>启用</a>";
            }
            return content;
        }

        function edit(id, categoryCode) {
            window.parent.addTab("修改型号", "/webapp/pages/product/series/add.html?id=" + id + "&categoryCode=" + categoryCode);
        }

        function disable(id) {
            $.messager.confirm("提示", "您确定禁用吗？", function (f) {
                if (f) {
                    $.ajax({
                        url: config.url + "/series/disable/" + id,
                        type: "post",
                        dataType: "json",
                        contentType: "application/json;charset=UTF-8",
                        xhrFields: {withCredentials: true},
                        beforeSend: function () {
                            $.messager.progress({
                                title: "请稍等",
                                interval: 50,
                                text: "操作进行中..."
                            });
                        },
                        complete: function (data) {
                            $.messager.progress("close");
                        },
                        success: function (data) {
                            if (data.code == 200) {
                                $.messager.alert("提示", "操作成功", "info", function () {
                                    searchBy(1, 100);
                                });
                            }else {
                                $.messager.alert("提示", data.msg, "error");
                            }
                        },
                        error: function (data) {
                        }
                    });
                }
            });
        }

        function enable(id) {
            $.messager.confirm("提示", "您确定禁用吗？", function (f) {
                if (f) {
                    $.ajax({
                        url: config.url + "/series/enable/" + id,
                        type: "post",
                        dataType: "json",
                        contentType: "application/json;charset=UTF-8",
                        xhrFields: {withCredentials: true},
                        beforeSend: function () {
                            $.messager.progress({
                                title: "请稍等",
                                interval: 50,
                                text: "操作进行中..."
                            });
                        },
                        complete: function (data) {
                            $.messager.progress("close");
                        },
                        success: function (data) {
                            if (data.code == 200) {
                                $.messager.alert("提示", "操作成功", "info", function () {
                                    searchBy(1, 100);
                                });
                            }else {
                                $.messager.alert("提示", data.msg, "error");
                            }
                        },
                        error: function (data) {
                        }
                    });
                }
            });
        }

        $("#ff").keydown(function (event) {
            var e = event || window.event;
            var keyCode = e.keyCode || e.which;
            if (keyCode == "13") {
                searchBy();
            }
        });

    </script>
</html>
